include_directories(${CMAKE_SOURCE_DIR}/src/xplatform)
# server
set(
  SERVER_SRC_FILES
  xregister_handle.cpp
  xregister_server.cpp
  main.cpp
)
include_directories(.)
add_executable(register_server ${SERVER_SRC_FILES})
include_directories(${CMAKE_SOURCE_DIR}/src/tool)
target_link_libraries(register_server PRIVATE xplatform protobuf protoc)
if(WIN32)
  target_link_libraries(register_server PRIVATE ws2_32)
endif()
set_out_path(register_server)
set_runtime_name(register_server)
add_subdirectory(register_client)
# watchdog
add_executable(watch_register_server ${CMAKE_SOURCE_DIR}/src/xplatform/watchdog.cpp)
set_out_path(watch_register_server)
set_runtime_name(watch_register_server)
# 设置安装路径
install(TARGETS register_server watch_register_server
    ARCHIVE DESTINATION lib
    LIBRARY DESTINATION lib
    RUNTIME DESTINATION bin
)
# 安装头文件
# install(FILES XSSLCtx.h XSSL.h
#     DESTINATION include/XSSL
# )
# 在安装时生成 start_watch_register_server 文件
install(CODE "
    file(WRITE ${CMAKE_INSTALL_PREFIX}/bin/start_watch_register_server.sh \"watch_register_server 3 register_server $1 $2 $3 $4 $5\")
    file(WRITE ${CMAKE_INSTALL_PREFIX}/bin/stop_watch_register_server.sh \"killall watch_register_server\")
    execute_process(COMMAND chmod +x ${CMAKE_INSTALL_PREFIX}/bin/start_watch_register_server.sh)
    execute_process(COMMAND chmod +x ${CMAKE_INSTALL_PREFIX}/bin/stop_watch_register_server.sh)
")